package com.woniuxy.commons.entity;

import java.util.List;

public class PageBean<T> {

	// 当前页的数据集合
	private List<T> beanList;
	// 页码，用户请求request
	private int pageIndex;
	// 页显示数据
	private int pageSize;
	// 总条数
	private int totalRecord;
	// 总页数
	private int totalpage;
	// 起死页数
	private int pageBegin;
	// 结束页数
	private int pageEnd;
	// 保存get请求的查询条件
	private String url;

	public PageBean() {
		super();
	}

	public PageBean(List<T> beanList, int pageIndex, int pageSize, int totalRecord, int totalpage) {
		super();
		this.beanList = beanList;
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
		this.totalRecord = totalRecord;
		this.totalpage = totalpage;
	}

	public List<T> getBeanList() {
		return beanList;
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getTotalRecord() {
		return totalRecord;
	}

	public int getTotalpage() {
		return totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
	}

	public void setBeanList(List<T> beanList) {
		this.beanList = beanList;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}

	public void setTotalpage(int totalpage) {
		this.totalpage = totalpage;
	}

	public int getPageBegin() {
		return pageBegin;
	}

	public int getPageEnd() {
		return pageEnd;
	}

	public void setPageBegin(int pageBegin) {
		this.pageBegin = pageBegin;
	}

	public void setPageEnd(int pageEnd) {
		this.pageEnd = pageEnd;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Override
	public String toString() {
		return "PageBean [beanList=" + beanList + ", pageIndex=" + pageIndex + ", pageSize=" + pageSize
				+ ", totalRecord=" + totalRecord + ", totalpage=" + totalpage + "]";
	}

	/**
	 * 设置页面标签只有十个
	 */
	public void setpageBeginAndpageEnd() {
		if (getTotalpage() < 10) {
			pageBegin = 1;
			pageEnd = getTotalpage();
		} else {
			pageBegin = pageIndex - 5;
			pageEnd = pageIndex + 4;
			if (pageBegin < 1) {
				pageBegin = 1;
				pageEnd = 10;
			}
			if (pageEnd > getTotalpage()) {
				pageBegin = getTotalpage() - 9;
				pageEnd = getTotalpage();
			}
		}
	}
}
